//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Collections.Generic;
using System.Windows.Markup;
using OpenLS.Spreadsheet.UI.Internals.Resources;

namespace OpenLS.Spreadsheet.UI.Internals
{
    [ContentProperty("Formats")]
    public class FormatCategory
    {
        public FormatCategory()
        {

        }

        public FormatCategory(string name, params NamedFormat[] formats): this(name, (IEnumerable<NamedFormat>)formats)
        {

            this.name = name;
            this.formats = new List<NamedFormat>(formats);
        }
        public FormatCategory(string name, IEnumerable< NamedFormat> formats)
        {
            this.name = name;
            this.formats = new List<NamedFormat>(formats);
        }
        private string name;

        public string CategoryName
        {
            get { return name; }
            set { name = value; }
        }
        private readonly List<NamedFormat> formats = new List<NamedFormat>();
        public List<NamedFormat> Formats
        {
            get { return formats; }
        }


        public static FormatCategory CreateDates(string name, string dateFormats)
        {
            return new FormatCategory(name, Enumerable.Select(dateFormats.Split('|'), ff => NamedFormat.CreateDateFormat (ff)));
        }
        public static IEnumerable<FormatCategory> AllCategories
        {
            get
            {
                yield return new FormatCategory("General",
                    NamedFormat.CreateNamedFormat("General", "General"));

                yield return new FormatCategory("Number",
                                                NamedFormat.CreateNamedFormat("1234", "0.00"),
                                                NamedFormat.CreateNamedFormat("0.00;[Red]0.00", "0.00;[Red]0.00"),
                                                NamedFormat.CreateNamedFormat("0.00;[Red]0.00", "0.00_);(0.00)"),
                                                NamedFormat.CreateNamedFormat("(1234.00)", "0.00_);[Red](0.00)"));

                yield return new FormatCategory("Currency",
                                                NamedFormat.CreateNamedFormat("$123", "$#,##0.00"),
                                                NamedFormat.CreateNamedFormat("$123", "$#,##0.00;[Red]$#,##0.00"),
                                                NamedFormat.CreateNamedFormat("($123)", "$#,##0.00_);($#,##0.00)"),
                                                NamedFormat.CreateNamedFormat("($123)", "$#,##0.00_);[Red]($#,##0.00)"));

                yield return new FormatCategory("Accounting",
                                                NamedFormat.CreateNamedFormat("$123", "_($* #,##0.00_);_($* (#,##0.00);_($* \"-\"??_);_(@_)"))
                    ;

                yield return FormatCategory.CreateDates(UIStringTable.Date, UIStringTable.DateFormats);
                /*  CreateDateFormat( "m/d/yyyy"),
                  CreateDateFormat(
                                    "[$-F800]dddd, mmmm dd, yyyy "),
                  CreateDateFormat("m/d;@"),
                  CreateDateFormat("m/d/yy;@"),
                  CreateDateFormat("m/d/yy;@"),
                  CreateDateFormat("[$-409]d-mmm;@"),
                  CreateDateFormat("[$-409]d-mmm-yy;@"),
                  CreateDateFormat("[$-409]dd-mmm-yy;@"),
                  CreateDateFormat("[$-409]mmm-yy;@"),
                  CreateDateFormat("[$-409]mmmm-yy;@"),
                  CreateDateFormat("[$-409]mmmm d, yyyy;@"),
                  CreateDateFormat("[$-409]m/d/yy h:mm AM/PM;@"),
                  CreateDateFormat("m/d/yy h:mm;@"),
                  CreateDateFormat("[$-409]mmmmm;@"),
                  CreateDateFormat("[$-409]mmmmm-yy;@"),
                  CreateDateFormat("m/d/yyyy;@"),
                  CreateDateFormat("[$-409]d-mmm-yyyy;@")/*); */

                yield return FormatCategory.CreateDates(UIStringTable.Time, UIStringTable.TimeFormats);
                                           //     NamedFormat.CreateDateFormat("[$-F400]h:mm:ss AM/PM"),
                                            ///    NamedFormat.CreateDateFormat("h:mm;@"),
                                           //     NamedFormat.CreateDateFormat("[$-409]h:mm AM/PM;@"),
                                           //     NamedFormat.CreateDateFormat("h:mm:ss;@"),
                                           //     NamedFormat.CreateDateFormat("[$-409]h:mm:ss AM/PM;@"),
                                           //     NamedFormat.CreateDateFormat("mm:ss.0;@"),
                                            //    NamedFormat.CreateDateFormat("[h]:mm:ss;@"),
                                          //      NamedFormat.CreateDateFormat("[$-409]m/d/yy h:mm AM/PM;@"),
                                          //      NamedFormat.CreateDateFormat("m/d/yy h:mm;@"));

                yield return new FormatCategory(UIStringTable.Percentage,
                                                NamedFormat.CreateNamedFormat("0.00%", "0.00%"));

                yield return new FormatCategory(UIStringTable.Fraction,
                                                NamedFormat.CreateNamedFormat("Up to one digit (1/4)", "# ?/?"),
                                                NamedFormat.CreateNamedFormat("Up to two digits (21/25)", "# ??/??"),
                                                NamedFormat.CreateNamedFormat("Up to three digits (312/943)", "# ???/???"),
                                                NamedFormat.CreateNamedFormat("As halves (1/2)", "# ?/2"),
                                                NamedFormat.CreateNamedFormat("As quarters (2/4)", "# ?/4"),
                                                NamedFormat.CreateNamedFormat("As heights (4/8)", "# ?/8"),
                                                NamedFormat.CreateNamedFormat("As sixteens (8/16)", "# ?/16"),
                                                NamedFormat.CreateNamedFormat("As tenth (3/10)", "# ?/10"),
                                                NamedFormat.CreateNamedFormat("As hundreds (31/100)", "# ?/100"));

                yield return new FormatCategory("Scientific",
                                                NamedFormat.CreateNamedFormat("0.00E+00", "0.00E+00"));

                yield
                return new FormatCategory("Text",
                                          NamedFormat.CreateNamedFormat("Text", "@"));

                yield return new FormatCategory("Special",
                                                NamedFormat.CreateNamedFormat("Zip code", "00000"),
                                                NamedFormat.CreateNamedFormat("Zip code+4", "00000-0000"),
                                                NamedFormat.CreateNamedFormat("Phone number", "[&lt;=9999999]###-####;(###) ###-####"),
                                                NamedFormat.CreateNamedFormat("Social security number", "000-00-0000"));

                yield return new FormatCategory("Custom");




            }
        }
    }

    [ContentProperty("Categories")]
    public class FormatCategories
    {
        private List<FormatCategory> categories = new List<FormatCategory>();

        public List<FormatCategory> Categories
        {
            get { return categories; }
            set { categories = value; }
        }
      
    }
}